<?php
/**
 * @package common
 */
require_once "_codemanager.php";

/**
 * Definitions which cannot be stored in a simple constant
 * @see Constants
 */
class Definitions {
	/** Availavle localities and their text representation */
	public static $SETUP_LOCALITIES = array();
	/** identification about initialized state of a singltion instance of this class */
	private static $initialized = false;
	/** Available groups and their text representation */
	public static $SETUP_GROUPS = array();
	
	/**
	 * Initialize Definitions
	 */
	public static function init() {
		if (!self::$initialized) {
			$cm = CodeManager::getCodeManager();
			
			self::$SETUP_LOCALITIES["p1"] = $cm->get("30040") . " 1";
			self::$SETUP_LOCALITIES["p2"] = $cm->get("30040") . " 2";
			self::$SETUP_LOCALITIES["p3"] = $cm->get("30040") . " 3";
			self::$SETUP_LOCALITIES["p4"] = $cm->get("30040") . " 4";
			self::$SETUP_LOCALITIES["p5"] = $cm->get("30040") . " 5";
			self::$SETUP_LOCALITIES["p6"] = $cm->get("30040") . " 6";
			self::$SETUP_LOCALITIES["p7"] = $cm->get("30040") . " 7";
			self::$SETUP_LOCALITIES["p8"] = $cm->get("30040") . " 8";
			self::$SETUP_LOCALITIES["p9"] = $cm->get("30040") . " 9";
			self::$SETUP_LOCALITIES["p10"] = $cm->get("30040") . " 10";
			self::$SETUP_LOCALITIES["pe"] = $cm->get("30040") . " - " . $cm->get("30041");
			self::$SETUP_LOCALITIES["pw"] = $cm->get("30040") . " - " . $cm->get("30042");
			self::$SETUP_LOCALITIES["other"] = $cm->get("30102");
			
			self::$initialized = true;
			
			self::$SETUP_GROUPS[Constants::GROUP_FULL] = $cm->get("30034");
			self::$SETUP_GROUPS[Constants::GROUP_RESTRICTED] = $cm->get("30035");
			self::$SETUP_GROUPS[Constants::GROUP_NONE] = $cm->get("30036");
			
		}
	}
	
	/**
	 * Get accurate text reprezentation for the locality from
	 * the locality id.
	 * As a safe method it throws an exception when locality id not found.
	 * 
	 * @param string $localityId - id of a locality
	 * @return string - textual reprezentation of locality
	 */
	static public function getSetupLocalitiesSafe(string $localityId) {
		return self::getSetupUniversalSafe($localityId, self::$SETUP_LOCALITIES);
	}
	
	/**
	 * Get accurate text reprezentation for the group from
	 * the group id.
	 * As a safe method it throws an exception when group id not found.
	 * 
	 * @param string $localityId - id of a group
	 * @return string - textual reprezentation of group
	 */
	static public function getSetupGroupsSafe($groupId) {
		return self::getSetupUniversalSafe($groupId, self::$SETUP_GROUPS);
	}
	
	/**
	 * Used by public methods from this class
	 * @see Definitions::getSetupGroupsSafe
	 * @see Definitions::getSetupLocalitiesSafe
	 */
	static private function getSetupUniversalSafe($id, $array) {
		if (isset($array[$id])) {
			return $array[$id];
		} else {
			throw new ExceptionIllegalState("Id '$id' doesn't exist in array.");
		}
	}
}
Definitions::init();
?>